package com.os.opencv.java.chapter5;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class Scale {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        //读取图像文件并在屏幕上显示
        Mat src = Imgcodecs.imread("/Users/matt/Pictures/111.jpg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //获取原图像尺寸
        float width = src.width();
        float height = src.height();

        //将原图像放大至1.2倍
        Mat dst1 = new Mat();
        float scale1 = 1.2f;
        Imgproc.resize(src, dst1, new Size(width * scale1, height * scale1));

        //将原图像缩小至0.8倍
        Mat dst2 = new Mat();
        float scale2 = 0.4f;
        Imgproc.resize(src, dst2, new Size(width * scale2, height * scale2));

        //在屏幕上显示放大和缩小后的图像
        HighGui.imshow("bigger", dst1);
        HighGui.waitKey(0);
        HighGui.imshow("smaller", dst2);
        HighGui.waitKey(0);

        System.exit(0);
    }
}
